package com.gitee.wsl.mathematics.algebraic.sample


import com.gitee.wsl.mathematics.algebraic.Ring
import com.gitee.wsl.mathematics.algebraic.number.NumericAlgebra
import com.gitee.wsl.mathematics.algebraic.op.Norm
import kotlin.math.abs

interface Int32ExtendedField: Ring<Int>, Norm<Int, Int>, NumericAlgebra<Int>

/**
 * A field for [Int] without boxing. Does not produce a corresponding ring element.
 */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
object Int32Ring :Int32ExtendedField {

    override val zero: Int get() = 0
    override val one: Int get() = 1

    override fun number(value: Number): Int = value.toInt()
    override fun add(left: Int, right: Int): Int = left + right
    override fun multiply(left: Int, right: Int): Int = left * right
    override fun norm(arg: Int): Int = abs(arg)

    override fun Int.unaryMinus(): Int = -this
    override fun Int.plus(arg: Int): Int = this + arg
    override fun Int.minus(arg: Int): Int = this - arg
    override fun Int.times(arg: Int): Int = this * arg
}

typealias IntRing = Int32Ring

val Int.Companion.algebra: Int32Ring get() = Int32Ring